// 分页查询
function serch_bean(pageNum){
    //form表单序列化
    var all_val = $("#asdasd").serializeArray();
    var pageN = pageNum;
    $.get("/myspringboot/selectUserAll",{map:all_val,pageNum:pageN},function(pageInfo){
        var aaaa = "";  //将后端返回的参数转化为一个字符串
        $("#checkOne").empty();
        var result = pageInfo.data.list;
        yibu(pageInfo.data.pages,pageInfo.data.pageNum);
        for (var i = 0; i < result.length; i++) {
            //循环遍历
            aaaa += "<tr><td>"+result[i].user.uId+"</td><td>" + result[i].user.uName + "</td><td>" + result[i].role.rName +"</td>" +
                "<td>" + result[i].user.uPassword + "</td><td>" + result[i].user.uState + "</td><td>" + result[i].user.uCompany +"</td>" +
                "<td>" + result[i].user.uAdress+ "</td><td>" + result[i].user.uPostalcode+ "</td><td>" + result[i].user.uContacts+"</td>" +
                "<td>" + result[i].user.uPhone+ "</td><td>" + result[i].user.uEmail+ "</td>" +
                "<td id='"+ result+"'><button  data-toggle=\"modal\" data-target=\"#myModal\">新增</button> " +
                "|<button  data-toggle=\"modal\" data-target=\"#myModal1\" onclick='selectUserByID("+result[i].user.uId+")'>修改</button>" +
                "|<a  href='/myspringboot/deleteUser?uId=" +result[i].user.uId+"'>删除</a></td></tr>";


        }
        $("#checkOne").append(aaaa);
    })

}
//多条件查询
function serch_bean1(pageNum){
    //form表单序列化
    var all_val = $("#asdasd").serializeArray();
    $.get("/myspringboot/selectUser",all_val,function(result){
        var aaaa = "";  //将后端返回的参数转化为一个字符串
        $("#checkOne").empty();
        for (var i = 0; i < result.length; i++) {
            //循环遍历
            aaaa += "<tr><td>"+result[i].user.uId+"</td><td>" + result[i].user.uName + "</td><td>" + result[i].role.rName +"</td>" +
                "<td>" + result[i].user.uPassword + "</td><td>" + result[i].user.uState + "</td><td>" + result[i].user.uCompany +"</td>" +
                "<td>" + result[i].user.uAdress+ "</td><td>" + result[i].user.uPostalcode+ "</td><td>" + result[i].user.uContacts+"</td>" +
                "<td>" + result[i].user.uPhone+ "</td><td>" + result[i].user.uEmail+ "<td>" +
                "<button  data-toggle=\"modal\" data-target=\"#myModal\">新增</button> " +
                "|<button  data-toggle=\"modal\" data-target=\"#myModal1\" onclick='selectUserByID("+result[i].user.uId+")'>修改</button>" +
                "|<a  href='/myspringboot/deleteUser?uId=" +result[i].user.uId+"'>删除</a></td></tr>";
        }
        $("#checkOne").append(aaaa);
    })

}

//添加用户
function lauser() {
    var v = $("#search_form").serializeArray();
    $.ajax({
        url:"/myspringboot/insertUser",
        data:v,
        type:"post",
        dataType:"json",
        success :function (result) {
            if(result=="SUCCESS"){
                alert("成功");
                aa();
                //location.replace(location.href)
            }else{
                alert("删除失败")
            }
        }
    })
}

//修改
function selectUserByID(uId) {
    //通过截取路径的字符串 来获取到参数
    // alert(uId);
    $.getJSON("/myspringboot/selectUserById", {uId:uId}, function (result13) {
        $("#uId").val(result13.uId);
        $("#name").val(result13.uName);
        $("#id").val(result13.rId);
        $("#password").val(result13.uPassword);
        $("#state").val(result13.uState);
        $("#company").val(result13.uCompany);
        $("#adress").val(result13.uAdress);
        $("#postalcode").val(result13.uPostalcode);
        $("#contacts").val(result13.uContacts);
        $("#phone").val(result13.uPhone);
        $("#email").val(result13.uEmail);
        //把id隐藏一下
    });
}
//修改方法
function xiugai(uId){
    var v = $("#search_form1").serializeArray();
    $.ajax({
        url:"/myspringboot/updateUser",
        data:v,
        type:"post",
        dataType:"json",
        success :function (result) {

        }
    })
}